<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>设计模式七大原则 | 学习笔记</title>
    <meta name="generator" content="VuePress 1.9.10">
    <link rel="icon" href="/favicon.ico">
    <script charset="utf-8" async="async" src="/js/jquery.min.js"></script>
    <script charset="utf-8" async="async" src="/js/global.js"></script>
    <script charset="utf-8" async="async" src="/js/fingerprint2.min.js"></script>
    <script>
              var _hmt = _hmt || [];
              (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?0b31b4c146bf7126aed5009e1a4a11c8";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
              })();
            </script>
    <meta name="description" content="记录学习笔记、项目心得、趟过的雷、踩过的坑">
    <meta property="article:modified_time" content="2024-03-12T06:13:40.000Z">
    <meta property="og:title" content="设计模式七大原则">
    <meta property="og:type" content="article">
    <meta property="og:url" content="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html">
    <meta name="twitter:title" content="设计模式七大原则">
    <meta name="twitter:url" content="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="robots" content="all">
    <meta name="author" content="青山">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="keywords" content="学习笔记, DDD抽奖系统，数据结构，重学Java设计模式, 字节码编程, 中间件, 手写Spring, 手写MyBatis，Java基础, 面经手册，面试题，API网关，SpringBoot Stater">
    <meta name="apple-mobile-web-app-capable" content="yes">
    
    <link rel="preload" href="/assets/css/0.styles.4e2267cf.css" as="style"><link rel="preload" href="/assets/css/styles.css?v=1722145213052" as="style"><link rel="preload" href="/assets/js/cg-styles.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-app.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-4.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-43.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-2.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-25.js?v=1722145213052" as="script">
    <link rel="stylesheet" href="/assets/css/0.styles.4e2267cf.css"><link rel="stylesheet" href="/assets/css/styles.css?v=1722145213052">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">学习笔记</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/md/nav/nav.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="读书&amp;笔记" class="dropdown-title"><span class="title">读书&amp;笔记</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/book/Java Multithread Programming/Java多线程编程核心技术（第3版）.html" class="nav-link">
  Java多线程编程核心技术（第3版）
</a></li><li class="dropdown-subitem"><a href="/md/book/OnJava中文版基础/第一章.html" class="nav-link">
  On Java 中文版 基础
</a></li><li class="dropdown-subitem"><a href="/md/sad/必修2-计算机基础.html" class="nav-link">
  架构师
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><span class="title">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java 基础
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/core/HelloJava.html" class="nav-link">
  Hello Java
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-变量.html" class="nav-link">
  Java 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-面向对象.html" class="nav-link">
  Java 面向对象
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/jvm/JVM-基础-类字节码详解.html" class="nav-link">
  JVM 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/jvm/GC-Java-垃圾回收基础知识.html" class="nav-link">
  GC
</a></li></ul></li><li class="dropdown-item"><h4>
          JUC
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/JUC并发编程.html" class="nav-link">
  JUC并发编程
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Spring" class="dropdown-title"><span class="title">Spring</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Spring
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Boot
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Cloud
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Security
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Session
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Data
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Batch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java框架" class="dropdown-title"><span class="title">Java框架</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Mybatis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MybatisPlus
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          日志框架
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          缓存
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          连接池
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          ShardingSphere
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="设计模式&amp;算法" class="dropdown-title"><span class="title">设计模式&amp;算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          设计模式
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/参考资料.html" class="nav-link">
  参考资料
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/设计模式七大原则.html" class="nav-link">
  设计模式七大原则
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/UML图.html" class="nav-link">
  UML图
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/Java设计模式.html" class="nav-link">
  Java设计模式
</a></li></ul></li><li class="dropdown-item"><h4>
          算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><span class="title">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Oracle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Redis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Elasticsearch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Kafka
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Mongodb
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Tomcat
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Nginx
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          RabbitMQ
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-简介.html" class="nav-link">
  Docker 简介
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-常用命令.html" class="nav-link">
  Docker 常用命令
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-镜像.html" class="nav-link">
  Docker 镜像
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-数据卷.html" class="nav-link">
  Docker 数据卷
</a></li></ul></li><li class="dropdown-item"><h4>
          K8s
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Git
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Maven
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Gradle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Idea
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/idea/插件.html" class="nav-link">
  插件
</a></li><li class="dropdown-subitem"><a href="/md/idea/常用设置.html" class="nav-link">
  常用设置
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="环境部署" class="dropdown-title"><span class="title">环境部署</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/db/mysql/MySQL-安装.html" class="nav-link">
  MySQL 安装
</a></li></ul></li><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="源码仓库" class="dropdown-title"><span class="title">源码仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/YiShanQingF/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhufanjia/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/md/nav/nav.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="读书&amp;笔记" class="dropdown-title"><span class="title">读书&amp;笔记</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/book/Java Multithread Programming/Java多线程编程核心技术（第3版）.html" class="nav-link">
  Java多线程编程核心技术（第3版）
</a></li><li class="dropdown-subitem"><a href="/md/book/OnJava中文版基础/第一章.html" class="nav-link">
  On Java 中文版 基础
</a></li><li class="dropdown-subitem"><a href="/md/sad/必修2-计算机基础.html" class="nav-link">
  架构师
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><span class="title">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java 基础
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/core/HelloJava.html" class="nav-link">
  Hello Java
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-变量.html" class="nav-link">
  Java 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-面向对象.html" class="nav-link">
  Java 面向对象
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/jvm/JVM-基础-类字节码详解.html" class="nav-link">
  JVM 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/jvm/GC-Java-垃圾回收基础知识.html" class="nav-link">
  GC
</a></li></ul></li><li class="dropdown-item"><h4>
          JUC
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/JUC并发编程.html" class="nav-link">
  JUC并发编程
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Spring" class="dropdown-title"><span class="title">Spring</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Spring
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Boot
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Cloud
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Security
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Session
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Data
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Batch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java框架" class="dropdown-title"><span class="title">Java框架</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Mybatis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MybatisPlus
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          日志框架
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          缓存
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          连接池
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          ShardingSphere
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="设计模式&amp;算法" class="dropdown-title"><span class="title">设计模式&amp;算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          设计模式
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/参考资料.html" class="nav-link">
  参考资料
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/设计模式七大原则.html" class="nav-link">
  设计模式七大原则
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/UML图.html" class="nav-link">
  UML图
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/Java设计模式.html" class="nav-link">
  Java设计模式
</a></li></ul></li><li class="dropdown-item"><h4>
          算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><span class="title">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Oracle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Redis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Elasticsearch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Kafka
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Mongodb
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Tomcat
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Nginx
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          RabbitMQ
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-简介.html" class="nav-link">
  Docker 简介
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-常用命令.html" class="nav-link">
  Docker 常用命令
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-镜像.html" class="nav-link">
  Docker 镜像
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-数据卷.html" class="nav-link">
  Docker 数据卷
</a></li></ul></li><li class="dropdown-item"><h4>
          K8s
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Git
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Maven
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Gradle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Idea
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/idea/插件.html" class="nav-link">
  插件
</a></li><li class="dropdown-subitem"><a href="/md/idea/常用设置.html" class="nav-link">
  常用设置
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="环境部署" class="dropdown-title"><span class="title">环境部署</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/db/mysql/MySQL-安装.html" class="nav-link">
  MySQL 安装
</a></li></ul></li><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="源码仓库" class="dropdown-title"><span class="title">源码仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/YiShanQingF/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhufanjia/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>设计模式</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/designPattern/参考资料.html" class="sidebar-link">参考资料</a></li><li><a href="/md/designPattern/设计模式七大原则.html" class="active sidebar-link">设计模式七大原则</a></li><li><a href="/md/designPattern/UML图.html" class="sidebar-link">UML图</a></li><li><a href="/md/designPattern/Java设计模式.html" class="sidebar-link">Java 设计模式</a></li></ul></section></li></ul> </aside> <div><main class="page"> <div class="theme-default-content content__default"><h1 id="设计模式七大原则"><a href="#设计模式七大原则" class="header-anchor">#</a> 设计模式七大原则</h1> <h2 id="设计模式内容介绍"><a href="#设计模式内容介绍" class="header-anchor">#</a> 设计模式内容介绍</h2> <h3 id="设计模式的重要性"><a href="#设计模式的重要性" class="header-anchor">#</a> 设计模式的重要性</h3> <ul><li>软件工程中，设计模式（design pattern）是对软件设计中普遍存在（反复出现）的各种问题，所提出的解决方案。这个术语是由埃里希·伽玛（Erich Gamma）等人在1990年代从建筑设计领域引入到计算机科学的</li> <li>面向对象(oo)=&gt;功能模块[设计模式+算法(数据结构)]=&gt;框架[使用到多种设计模式]=&gt;架构 [服务器集群]</li></ul> <h3 id="设计模式的目的"><a href="#设计模式的目的" class="header-anchor">#</a> 设计模式的目的</h3> <p>编写软件过程中，面临着来自耦合性，内聚性以及可维护性，可扩展性，重用性，灵活性 等多方面的挑战，设计模式是为了让程序(软件)，具有更好的</p> <ul><li>代码重用性 (即：相同功能的代码，不用多次编写)</li> <li>可读性 (即：编程规范性, 便于其他程序员的阅读和理解)</li> <li>可扩展性 (即：当需要增加新的功能时，非常的方便，称为可维护)</li> <li>可靠性 (即：当我们增加新的功能后，对原来的功能没有影响)</li> <li>使程序呈现高内聚，低耦合的特性</li></ul> <blockquote><p>设计模式包含了面向对象的精髓，“懂了设计模式，你就懂了面向对象分析和设计（OOA/D）的精要”</p></blockquote> <h2 id="设计模式七大原则-2"><a href="#设计模式七大原则-2" class="header-anchor">#</a> 设计模式七大原则</h2> <div class="language- line-numbers-mode"><pre class="language-text"><code>接口隔离原则
单一职责原则
依赖倒转(倒置)原则
里氏替换原则
开闭原则
迪米特法则
合成复用原则
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="单一职责原则-single-responsiblility-principle"><a href="#单一职责原则-single-responsiblility-principle" class="header-anchor">#</a> 单一职责原则 Single Responsiblility Principle</h3> <blockquote><p>一个接口或类只有一个职责，单一职责用职责来衡量接口或类设计是否优良，但职责是不可度量的，因项目而异，因环境而异。</p></blockquote> <ul><li>降低类的复杂度，一个类只负责一项职责。</li> <li>提高类的可读性，可维护性</li> <li>降低变更引起的风险</li> <li>通常情况下，我们应当遵守单一职责原则，只有逻辑足够简单，才可以在代码级违反单一职责原则；只有类中方法数量足够少，可以在方法级别保持单一职责原则</li></ul> <h3 id="接口隔离原则-interface-segregation-principle"><a href="#接口隔离原则-interface-segregation-principle" class="header-anchor">#</a> 接口隔离原则 Interface Segregation Principle</h3> <blockquote><p>使用多个隔离接口，比使用单个接口好。一个接口只服务于一个子模块和业务逻辑。</p></blockquote> <ul><li>客户端不应该依赖它不需要的接口，即<strong>一个类对另一个类的依赖应该建立在最小的接口上</strong> <img alt="" data-src="/images/designPattern/%E6%8E%A5%E5%8F%A3%E9%9A%94%E7%A6%BB-%E5%AF%BC%E5%87%BA.png" loading="lazy" class="lazy"></li></ul> <h3 id="依赖倒转-倒置-原则-dependence-inversion-principle"><a href="#依赖倒转-倒置-原则-dependence-inversion-principle" class="header-anchor">#</a> 依赖倒转(倒置)原则 Dependence Inversion Principle</h3> <blockquote><p>面向接口编程，每个类尽量都有接口或者抽象类，抽象不应该依赖于细节，细节应当依赖于抽象，要针对接口编程。</p></blockquote> <ul><li>高层模块不应该依赖低层模块，二者都应该依赖其抽象</li> <li>抽象不应该依赖细节，细节应该依赖抽象</li> <li>依赖倒转(倒置)的中心思想是面向接口编程</li> <li>依赖倒转原则是基于这样的设计理念：相对于细节的多变性，抽象的东西要稳定的多。以抽象为基础搭建的架构比以细节为基础的架构要稳定的多。在java中，抽象指的是接口或抽象类，细节就是具体的实现类</li> <li>使用接口或抽象类的目的是制定好规范，而不涉及任何具体的操作，把展现细节的任务交给他们的实现类去完成</li></ul> <p><strong>依赖关系传递的三种方式和应用案例</strong></p> <ul><li>接口传递（方法参数）</li> <li>构造方法传递（）</li> <li>setter方式传递</li></ul> <p><strong>注意事项和细节</strong></p> <ul><li>低层模块尽量都要有抽象类或接口，或者两者都有，程序稳定性更好.</li> <li>变量的声明类型尽量是抽象类或接口, 这样我们的变量引用和实际对象间，就存在一个缓冲层，利于程序扩展和优化</li> <li>继承时遵循里氏替换原则</li></ul> <h3 id="里氏替换原则-liskov-substitution-principle"><a href="#里氏替换原则-liskov-substitution-principle" class="header-anchor">#</a> 里氏替换原则 Liskov Substitution Principle</h3> <blockquote><p>只要父类可以出现的地方，之类就可以出现，而且替换为之类也不会产生任何错误或异常，使用者可能根本不需要知道是父类还是子类，反过来不适用。</p></blockquote> <p><strong>OO中的继承性的思考和说明</strong></p> <ul><li>继承包含这样一层含义：父类中凡是已经实现好的方法，实际上是在设定规范和契约，虽然它不强制要求所有的子类必须遵循这些契约，但是如果子类对这些已经实现的方法任意修改，就会对整个继承体系造成破坏。</li> <li>继承在给程序设计带来便利的同时，也带来了弊端。比如使用继承会给程序带来侵入性，程序的可移植性降低，增加对象间的耦合性，如果一个类被其他的类所继承，则当这个类需要修改时，必须考虑到所有的子类，并且父类修改后，所有涉及到子类的功能都有可能产生故障</li></ul> <p><strong>基本介绍</strong></p> <ul><li>里氏替换原则(Liskov Substitution Principle)在1988年，由麻省理工学院的以为姓里的女士提出的。</li> <li>如果对每个类型为T1的对象o1，都有类型为T2的对象o2，使得以T1定义的所有程序的对象o1都代换成o2时，程序P的行为没有发生变化，那么类型T2是类型T1的子类型。换句话说，所有引用基类的地方必须能透明地使用其子类的对象。</li> <li>在使用继承时，遵循里氏替换原则，在子类中<strong>尽量</strong>不要重写父类的方法</li> <li>里氏替换原则告诉我们，继承实际上让两个类耦合性增强了， <strong>在适当的情况下，可以通过聚合，组合，依赖 来解决问题</strong>。</li></ul> <h3 id="开闭原则-open-closed-principle"><a href="#开闭原则-open-closed-principle" class="header-anchor">#</a> 开闭原则 Open Closed Principle</h3> <blockquote><p>对扩展开发，对修改关闭。在程序需要进行拓展的时候，不能去修改原有的代码，实现一个热插拔的效果。</p></blockquote> <p><strong>基本介绍</strong></p> <ul><li>开闭原则（Open Closed Principle）是编程中最基础、最重要的设计原则</li> <li>一个软件实体如类，模块和函数应该对扩展开放(对提供方)，对修改关闭(对使用方)。用抽象构建框架，用实现扩展细节。</li> <li>当软件需要变化时，尽量<strong>通过扩展</strong>软件实体的行为来实现变化，而<strong>不是通过修改</strong>已有的代码来实现变化。</li> <li>编程中遵循其它原则，以及使用设计模式的目的就是遵循<strong>开闭原则</strong>。</li></ul> <h3 id="迪米特法则-demeter-principle"><a href="#迪米特法则-demeter-principle" class="header-anchor">#</a> 迪米特法则 Demeter Principle</h3> <blockquote><p>最少知道原则。类应该对调用的类知道的最少。减少类间耦合，实现弱耦合。</p></blockquote> <p><strong>基本介绍</strong></p> <ul><li>一个对象应该对其他对象保持最少的了解</li> <li>类与类关系越密切，耦合度越大</li> <li>迪米特法则(Demeter Principle)又叫 最少知道原则，即一个类对自己依赖的类知道的越少越好。也就是说，对于被依赖的类不管多么复杂，都尽量将逻辑封装在类的内部。对外除了提供的public 方法，不对外泄露任何信息</li> <li>迪米特法则还有个更简单的定义：只与直接的朋友通信</li> <li><strong>直接的朋友</strong>：每个对象都会与其他对象有耦合关系，只要两个对象之间有耦合关系，我们就说这两个对象之间是朋友关系。耦合的方式很多，依赖，关联，组合，聚合等。其中，我们称出现成员变量，方法参数，方法返回值中的类为直接的朋友，而出现在局部变量中的类不是直接的朋友。也就是说，陌生的类最好不要以局部变量的形式出现在类的内部。</li></ul> <p><strong>迪米特法则注意事项和细节</strong></p> <ul><li>迪米特法则的核心是 降低类之间的耦合</li> <li>但是注意：由于每个类都减少了不必要的依赖，因此迪米特法则只是要求降低类间(对象间)耦合关系， 并不是要求完全没有依赖关系</li></ul> <h3 id="合成复用原则-composite-reuse-principle"><a href="#合成复用原则-composite-reuse-principle" class="header-anchor">#</a> 合成复用原则 Composite Reuse Principle</h3> <p><strong>原则是尽量使用合成/聚合的方式，而不是使用继承</strong></p> <h3 id="设计原则核心思想"><a href="#设计原则核心思想" class="header-anchor">#</a> 设计原则核心思想</h3> <ul><li>找出应用中可能需要变化之处，把它们独立出来，不要和那些不需要变化的代码混在一起。</li> <li>针对接口编程，而不是针对实现编程。</li> <li>为了交互对象之间的松耦合设计而努力</li></ul></div> <!----> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/YiShanQingF/LearningNotes/edit/master/docs/md/designPattern/设计模式七大原则.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2024/3/12</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/md/designPattern/参考资料.html" class="prev">
          参考资料
        </a></span> <span class="next"><a href="/md/designPattern/UML图.html">
          UML图
        </a>
        →
      </span></p></div> </main></div> <aside class="page-sidebar"> <div class="page-side-toolbar"><div class="option-box-toc-fixed"><div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:650px"><div style="font-weight:bold;text-align:center;">设计模式七大原则</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式内容介绍" class="toc-sidebar-link">设计模式内容介绍</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式的重要性" class="toc-sidebar-link">设计模式的重要性</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式的目的" class="toc-sidebar-link">设计模式的目的</a></li></ul></li><li><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式七大原则-2" class="toc-sidebar-link">设计模式七大原则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#单一职责原则-single-responsiblility-principle" class="toc-sidebar-link">单一职责原则 Single Responsiblility Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#接口隔离原则-interface-segregation-principle" class="toc-sidebar-link">接口隔离原则 Interface Segregation Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#依赖倒转-倒置-原则-dependence-inversion-principle" class="toc-sidebar-link">依赖倒转(倒置)原则 Dependence Inversion Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#里氏替换原则-liskov-substitution-principle" class="toc-sidebar-link">里氏替换原则 Liskov Substitution Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#开闭原则-open-closed-principle" class="toc-sidebar-link">开闭原则 Open Closed Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#迪米特法则-demeter-principle" class="toc-sidebar-link">迪米特法则 Demeter Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#合成复用原则-composite-reuse-principle" class="toc-sidebar-link">合成复用原则 Composite Reuse Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计原则核心思想" class="toc-sidebar-link">设计原则核心思想</a></li></ul></li></ul></div></div></div></div></div> <div class="option-box-toc-over"><img src="/images/system/toc.png" class="nozoom"> <span class="show-txt">目录</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:550px"><div style="font-weight:bold;text-align:center;">设计模式七大原则</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式内容介绍" class="toc-sidebar-link">设计模式内容介绍</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式的重要性" class="toc-sidebar-link">设计模式的重要性</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式的目的" class="toc-sidebar-link">设计模式的目的</a></li></ul></li><li><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计模式七大原则-2" class="toc-sidebar-link">设计模式七大原则</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#单一职责原则-single-responsiblility-principle" class="toc-sidebar-link">单一职责原则 Single Responsiblility Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#接口隔离原则-interface-segregation-principle" class="toc-sidebar-link">接口隔离原则 Interface Segregation Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#依赖倒转-倒置-原则-dependence-inversion-principle" class="toc-sidebar-link">依赖倒转(倒置)原则 Dependence Inversion Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#里氏替换原则-liskov-substitution-principle" class="toc-sidebar-link">里氏替换原则 Liskov Substitution Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#开闭原则-open-closed-principle" class="toc-sidebar-link">开闭原则 Open Closed Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#迪米特法则-demeter-principle" class="toc-sidebar-link">迪米特法则 Demeter Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#合成复用原则-composite-reuse-principle" class="toc-sidebar-link">合成复用原则 Composite Reuse Principle</a></li><li class="toc-sidebar-sub-header"><a href="/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html#设计原则核心思想" class="toc-sidebar-link">设计原则核心思想</a></li></ul></li></ul></div></div></div></div></div> <div class="option-box"><img src="/images/system/wechat.png" class="nozoom"> <span class="show-txt">手机看</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.9rem">微信扫一扫</span> <img height="180px" src="https://api.qrserver.com/v1/create-qr-code/?data=http://zhufj.com/md/designPattern/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E4%B8%83%E5%A4%A7%E5%8E%9F%E5%88%99.html" style="margin:10px;">
              可以<b>手机看</b>或分享至<b>朋友圈</b></div></div></div></div> <div class="option-box"><a title="点击切换全屏" style="text-align:center;padding-left:2px;"><img src="/images/system/full.png" width="30px" class="nozoom"> <span style="color:gray;font-size:11px;font-weight:400;">全屏看</span></a></div> <div class="option-box"><img src="/images/system/toggle.png" width="30px" class="nozoom"> <span class="show-txt">左栏</span></div> <div class="option-box"><img src="/images/system/download.png" width="25px" class="nozoom"> <span class="show-txt">下资料</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">扫描公众号，回复<span style="color:red;">“1024”</span>下载<span style="color:red;">100GB+</span>大学到毕业分阶段学习技术资料、PDF书籍、实战项目、简历模板等「无任何套路」</span> <img src="/images/personal/qrcode.jpg" height="180px" style="margin:10px;"> <b>公众号:</b> BJCoder
            </div></div></div></div> <div title="参考资料" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/designPattern/参考资料.html"><img src="/images/system/pre2.png" width="30px" class="nozoom"> <span class="show-txt">上一篇</span></a></div> <div title="UML图" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/designPattern/UML图.html"><img src="/images/system/next2.png" width="30px" class="nozoom"> <span class="show-txt">下一篇</span></a></div></div>  <div class="page-side-sitemap"><div class="option-box"><img src="/images/system/sitemap.png" class="nozoom img"> <span class="show-txt">站点图</span> <div class="sitemap-container"><h4>站点导航图</h4> <table class="sitemap-table"><tr><td nowrap="nowrap"><div class="sitemap-col-group">常用搜索</div></td> <td><div class="sitemap-col-item"><a href="http://www.baidu.com/" target="_blank" title="百度">  
          百度
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.google.com/" target="_blank" title="Google">  
          Google
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.bing.com/" target="_blank" title="Bing">  
          Bing
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://github.com" target="_blank" title="Github">  
          Github
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.programcreek.com/java-api-examples/index.php" target="_blank" title="搜代码">  
          搜代码
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div></td> <!----></tr><tr><td nowrap="nowrap"><div class="sitemap-col-group">技术社区</div></td> <td><div class="sitemap-col-item"><a href="http://www.csdn.net/" target="_blank" title="CDSN">  
          CDSN
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.cnblogs.com/" target="_blank" title="博客园">  
          博客园
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.oschina.net" target="_blank" title="OSChina">  
          OSChina
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://segmentfault.com/" target="_blank" title="思否">  
          思否
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://juejin.im" target="_blank" title="掘金">  
          掘金
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.linuxidc.com/" target="_blank" title="Linux公社">  
          Linux公社
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.ibm.com/developerworks/cn/" target="_blank" title="IBM 开发者">  
          IBM 开发者
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://stackoverflow.com" target="_blank" title="StackOverflow">  
          StackOverflow
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div></td> <!----></tr></table></div></div></div> <!----> </aside></div><div class="global-ui"><div class="pay-read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="pay-read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="pay-read-more-btn" target="_blank" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">付费阅读</a></div></div></div>
    <script src="/assets/js/cg-styles.js?v=1722145213052" defer></script><script src="/assets/js/cg-4.js?v=1722145213052" defer></script><script src="/assets/js/cg-43.js?v=1722145213052" defer></script><script src="/assets/js/cg-2.js?v=1722145213052" defer></script><script src="/assets/js/cg-25.js?v=1722145213052" defer></script><script src="/assets/js/cg-app.js?v=1722145213052" defer></script>
  </body>
</html>
